﻿/// <reference path="jquery-1.10.2.js" />
//加入购物车
function add_cart(host) {
    var goodsid = $(".topRight #goodsid").val();
    var clolerid = $(".topRight #colorid").val();
    var sizeid = $(".topRight #sizeid").val();
    var goods_count = $(".topRight #goods_count").val();
    var url = host + "cart/addcart.html";
    if (sizeid == "" || sizeid == null) {
        layer.msg('请选择衣服尺寸', { icon: 5 }, function () { })
        return false;
    }
    if (clolerid == "" || clolerid == null) {
        layer.msg('请选择衣服颜色', { icon: 7 }, function () { });
        return false;
    }
    $.post(url, { 'goodsid': goodsid, 'clolerid': clolerid, 'sizeid': sizeid, 'goods_count': goods_count,'backurl':window.location.href }, function (data) {
        var jsonData = $.parseJSON(data);
        if (jsonData.Statu == 'ok') {
            var old_count = parseInt($(".logoAndLogin .cart").find('span').text());
            $(".logoAndLogin .cart").find('span').text(old_count + 1)
            $.Success(jsonData);
        } else {
            $.Success(jsonData);
        }
    });
}

function get_cart_after_login(host) {
    var url = host + "cart/get_cart_after_login.html";
    $.get(url, null, function (data) {
        if (data != null && data != "") {
            var fun = data.split('|')[0];
            var count_html = data.split('|')[1];
            var obj = $(".logoAndLogin .cart");
            obj.attr("href", "javascript:" + fun)
            obj.html(count_html);
        } else {

        }
    });
}

function get_cartlist(host) {
    var url = "/cart/cartlist.html?backurl="+window.location.href;
    layer.open({
            type: 2,
            title: false,
            maxmin: false,
            shadeClose: false, //开启点击遮罩关闭层
            area: ['811px', '441px'],
            offset: ['100px', ''],
            closeBtn: 0,
            content: url
        });
}